package org.wendu.wdoa.common.page;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;


import java.util.HashMap;
import java.util.List;
import java.util.Map;

public class PageUtils {

    public  static <T> Map<String,Object> getPage(PageParam pageParam,QeuryAction<T> action){
        PageHelper.startPage(pageParam);//此语句一定要紧挨着查询之前执行
        List<T> list = action.query();
        PageInfo<T> pageInfo = new PageInfo<>(list);//此语句一定要紧挨着查询之后执行

        //....
        Map<String , Object> page = new HashMap<String, Object>();
        page.put("current",pageInfo.getPageNum());//当前页码
        page.put("pageSize",pageInfo.getPageSize());//每页记录数
        page.put("total",pageInfo.getTotal());//总记录数
        page.put("pages",pageInfo.getPages());

        page.put("first",1);
        page.put("pre",pageInfo.getPrePage());//上页码
        page.put("next",pageInfo.getNextPage());//下页码
        page.put("last",pageInfo.getPages());//尾页码

        page.put("list",pageInfo.getList());//当前页数据记录
        page.put("currSize",pageInfo.getSize());//当前页实际记录数
        return page;
    }


}
